package com.laoye.mapper;

import com.laoye.bean.User;
import com.laoye.dto.*;
import org.apache.ibatis.annotations.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Mapper
public interface UserMapper {

    @Update("update user set phone=#{userInfo.phone},nickname=#{userInfo.nickname} ,email=#{userInfo.email} where id=#{userInfo.id}")
    void editUser(@Param("userInfo") UserEditDTO userInfo);  //修改用户信息

    @Select("select username from user where id=#{id} and is_deleted=0")
    String findUsername(@Param("id") Integer id);  //根据id查找其他用户

    @Insert("insert into user(username,password,email) values(#{register.username},#{register.password},#{register.email})")
    void register(@Param("register") RegisterDTO registerDTO);  //用户注册

    @Select("select *from user where username=#{login.username} and is_deleted=0")
    User login(@Param("login") LoginDTO loginDTO);  //用户登录

    @Update("update user set password=#{pwdEditDTO.newPassword} where id=#{pwdEditDTO.id}")
    void updatePassword(@Param("pwdEditDTO") PwdEditDTO pwdEditDTO); //修改密码


    List<UserPageDTO> getUsersPage(@Param("keyword") String keyword);  //搜索框模糊查询


    @Update("update user set avatar_url= #{file} where id= #{id}")
    void updateAvatar(@Param("file") String file, @Param("id") Integer id);

    @Select("select avatar_url from user where id= #{id}")
    String getAvatarUrl(@Param("id") Integer id);

    @Select("select * from user where username= #{username}")
    User getUserByName(@Param("username") String username);

    @Select("select * from user where id= #{user_id}")
    User getUserById(@Param("user_id") Integer user_id);

    //获取用户邮箱,像邮箱发送邮件告诉用户发生的事件
    @Select("select email from user where id=#{id}")
    String getEmail(@Param("id") Integer id);
}
